<?php

class Nld_Auth_Users_Db implements Zend_Auth_Adapter_Interface
{
	public function __construct($username, $password)
	{
		$this->username = $username;
		$this->password = $password;
	}
  public function authenticate()
	{
		$dbtable	= Nld_Models::getTable('Users');
		$mesasge 	= array();
		$user 		= $dbtable->fetchRow('`username` = "'.$this->username.'" AND `status` > 0');
		
		if(($user !== null)&&($user->password == md5($this->password.$user->salt)))
		{
			return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $user);
		}
		
		$mesasge['login'] = 'Kiểm tra lại tài khoản và mật khẩu';
		return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null, $mesasge);
	}
}